<?php

declare (strict_types=1);
/**
 * @copyright 深圳市易果网络科技有限公司
 * @version 1.0.0
 * @link https://dayiguo.com
 */
namespace App\Controller\user;

use App\Dao\AdvertisingDao;
use App\Dao\CouponCategoryDao;
use App\Service\User\BusinessService;
use App\Middleware\User\UserMiddleware;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\AutoController;
use Hyperf\HttpServer\Annotation\Middleware;

/**
 * 首页控制器
 *
 * @AutoController()
 * @Middleware(UserMiddleware::class)
 * @author 刘兴永(aile8880@qq.com)
 * @package \App\Controller\user
 */
class MainController extends Controller
{
    /**
     * 广告 Dao
     *
     * @Inject
     * @var AdvertisingDao
     */
    private $advertising_dao;

    /**
     * 折扣券分类 Dao
     *
     * @Inject
     * @var CouponCategoryDao
     */
    private $coupon_category_dao;

    /**
     * @Inject
     * @var BusinessService
     */
    private $business_service;

    /**
     * 首页综合接口
     */
    public function index()
    {
        $longitude = (float)$this->request->input('longitude', '114.082581');

        $latitude = (float)$this->request->input('latitude', '22.624509');

        // 首页轮播广告
        $banner = $this->advertising_dao->getAdvertisingByType(1);

        // 附近商家
        $shop = $this->business_service->geoCalculator(0, $longitude,$latitude,[]);

        $this->success([
            'banner' => $banner,
            'shop' => $shop
        ]);
    }

    /**
     * 店铺
     */
    public function store()
    {
        $business_id = (int)$this->request->input('business_id', 0);

        $result = $this->business_service->store( $business_id );

        $this->success($result);
    }

    /**
     * 热词列表
     */
    public function hot_words_list()
    {
        $this->success(gConfig('hot_search'));
    }
}